import { BaseSelectUserMark } from '@src/component/common/BaseSelectUser/types';
/* types */
import { 
  BaseSelectUserMultiAllDefaultOptionsType, 
  BaseSelectUserMultiDepartmentAndRoleDefaultOptionsType, 
  BaseSelectUserMultiDepartmentAndUserDefaultOptionsType, 
  BaseSelectUserMultiDepartmentDefaultOptionsType, 
  BaseSelectUserMultiServiceProviderDefaultOptionsType, 
  BaseSelectUserMultiUserDefaultOptionsType, 
  BaseSelectUserSingleUserDefaultOptionsType 
} from '@src/component/common/BaseSelectUser/types'
/* model */
import { 
  BaseSelectUserMarkTypeEnum, 
  BaseSelectUserSearchMoreTypeEnum, 
  BaseSelectUserTypeIdEnum 
} from '@src/component/common/BaseSelectUser/model/enum'
import { 
  CustomerServiceCloudTextFunction, 
  ServiceCloudTextFunction, 
  SHBProductLineEnum,
  UnAllotUserFunction
} from '@shb-lib/tenant';
import { SelectUserComponentRole } from '@src/component/common/BaseSelectUser/model/interface';
/* images */
import { getOssUrl } from '@src/util/assets'
const DefaultHead = getOssUrl('avatar.png')
/* util */
import { t } from '@src/locales'
import { randomString } from '@src/util/lang/string';

// 最大选人数量
const BaseSelectUserMax = 100

// 选人组件配置 - 注入键名
const BaseSelectUserOptionProvideKey = Symbol('BaseSelectUserOptionProvideKey')

// 选人组件远程获取数据防抖时间
const BaseSelectUserFetchDebounceTime = 500

// 选人组件禁用选择的id
const BaseSelectUserDisabledSelectId = '0'

// 选人组件 单选人员默认配置
const BaseSelectUserDefaultSingleUserOptions: BaseSelectUserSingleUserDefaultOptionsType = {
  max: 1,
  isCanChooseUser: true,
  isCanChooseDepartment: false,
  isCanChooseRole: false,
  isCanChooseServiceProvider: false,
  selectedUsers: [],
  selectedDepartments: [],
  selectedRoles: [],
  selectedServiceProviders: [],
}

// 选人组件 多选人员默认配置
const BaseSelectUserDefaultMultiUserOptions: BaseSelectUserMultiUserDefaultOptionsType = {
  isCanChooseUser: true,
  isCanChooseDepartment: false,
  isCanChooseRole: false,
  isCanChooseServiceProvider: false,
  selectedDepartments: [],
  selectedRoles: [],
  selectedServiceProviders: [],
}

// 选人组件 多选部门 默认配置
const BaseSelectUserDefaultMultiDepartmentOptions: BaseSelectUserMultiDepartmentDefaultOptionsType = {
  isCanChooseUser: false,
  isCanChooseDepartment: true,
  isCanChooseRole: false,
  isCanChooseServiceProvider: false,
  showRole: false,
  showServiceProvider: false,
  showDelete: false,
  isShowUser: false,
  isShowSearch: false,
  selectedRoles: [],
  selectedUsers: [],
  selectedServiceProviders: [],
}

// 选人组件 多选部门人员 默认配置
const BaseSelectUserDefaultMultiDepartmentUserOptions: BaseSelectUserMultiDepartmentDefaultOptionsType = {
  isCanChooseUser: true,
  isCanChooseDepartment: false,
  isCanChooseRole: false,
  isCanChooseServiceProvider: false,
  showRole: false,
  showServiceProvider: false,
  showDelete: false,
  isShowUser: true,
  isShowSearch: true,
  selectedRoles: [],
  selectedUsers: [],
  selectedServiceProviders: [],
}

// 选人组件 多选部门和角色默认配置
const BaseSelectUserDefaultMultiDepartmentAndRoleOptions: BaseSelectUserMultiDepartmentAndRoleDefaultOptionsType = {
  isCanChooseUser: false,
  isCanChooseDepartment: true,
  isCanChooseRole: true,
  isCanChooseServiceProvider: false,
  selectedServiceProviders: [],
  selectedUsers: [],
  showServiceProvider: false,
  showDelete: false,
  isShowUser: false,
  isShowSearch: false
}

// 选人组件 多选 服务商 默认配置
const BaseSelectUserDefaultMultiServiceProviderOptions: BaseSelectUserMultiServiceProviderDefaultOptionsType = {
  isCanChooseUser: false,
  isCanChooseDepartment: false,
  isCanChooseRole: false,
  isCanChooseServiceProvider: true,
  selectedUsers: [],
  selectedDepartments: [],
  selectedRoles: [],
  showServiceProvider: true,
  showCancel: false,
  showDelete: false,
  isShowUser: false,
  isShowSearch: false,
  showRole: false,
  showDepartment: false,
}

// 选人组件 多选部门和人员默认配置
const BaseSelectUserDefaultMultiDepartmentAndUserOptions: BaseSelectUserMultiDepartmentAndUserDefaultOptionsType = {
  isCanChooseUser: true,
  isCanChooseDepartment: true,
  isCanChooseRole: false,
  isCanChooseServiceProvider: false,
  selectedRoles: [],
  selectedServiceProviders: [],
}

// 选人组件 多选所有默认配置
const BaseSelectUserDefaultMultiAllOptions: BaseSelectUserMultiAllDefaultOptionsType = {
  isCanChooseUser: true,
  isCanChooseDepartment: true,
  isCanChooseRole: true,
  isCanChooseServiceProvider: true,
}

const BaseSelectUserDefaultLogo: Record<string, string> = {
  [BaseSelectUserTypeIdEnum.Department]: 'https://shb-pro.oss-cn-hangzhou.aliyuncs.com/user/select_tag.png',
  [BaseSelectUserTypeIdEnum.Tag]: 'https://shb-pro.oss-cn-hangzhou.aliyuncs.com/user/select_tag.png',
  [BaseSelectUserTypeIdEnum.Role]: 'https://shb-pro.oss-cn-hangzhou.aliyuncs.com/user/select_role.png',
  [BaseSelectUserTypeIdEnum.ServiceProvider]: 'https://shb-pro.oss-cn-hangzhou.aliyuncs.com/user/select_sp.png',
  [BaseSelectUserTypeIdEnum.User]: DefaultHead,
}

const BaseSelectUserBaseWindowDefaultOptions: Record<string, any> = {
  id: `base-select-user-window`,
  storeStatus: true
}

const BaseSelectUserSearchMoreTypeNameMap = {
  [BaseSelectUserSearchMoreTypeEnum.Organization]: t('common.base.member'),
  [BaseSelectUserSearchMoreTypeEnum.ServiceProvider]: t('common.base.serviceProvider'),
}

// 选人组件 动态获取 tab
const BaseSelectUserDynamicTab: BaseSelectUserMark = {
  type: BaseSelectUserMarkTypeEnum.Dynamic,
  name: t('component.baseSelectUser.dynamicGain')
}

const ProductLineRoleMap: Record<string, SelectUserComponentRole> = {
  [SHBProductLineEnum.BusinessServiceCloud]: {
    id: randomString(), 
    name: ServiceCloudTextFunction(),
    isServiceCloud: true,
    isHideCheckbox: true,
    logo: '',
    typeId: BaseSelectUserTypeIdEnum.Role,
    productLine: SHBProductLineEnum.BusinessServiceCloud,
    userCount: 0
  },
  [SHBProductLineEnum.CustomerServiceCloud]: {
    id: randomString(), 
    name: CustomerServiceCloudTextFunction(),
    isCustomerServiceCloud: true,
    isHideCheckbox: true,
    logo: '',
    typeId: BaseSelectUserTypeIdEnum.Role,
    productLine: SHBProductLineEnum.BusinessServiceCloud,
    userCount: 0
  },
  [SHBProductLineEnum.UnAllot]: {
    id: randomString(), 
    name: UnAllotUserFunction(),
    logo: '',
    isHideCheckbox: true,
    typeId: BaseSelectUserTypeIdEnum.Role,
    productLine: SHBProductLineEnum.UnAllot,
    userCount: 0
  }
}

export {
  BaseSelectUserMax,
  BaseSelectUserOptionProvideKey,
  BaseSelectUserFetchDebounceTime,
  BaseSelectUserDisabledSelectId,
  BaseSelectUserDefaultSingleUserOptions,
  BaseSelectUserDefaultMultiUserOptions,
  BaseSelectUserDefaultMultiDepartmentOptions,
  BaseSelectUserDefaultMultiDepartmentAndUserOptions,
  BaseSelectUserDefaultMultiAllOptions,
  BaseSelectUserDefaultLogo,
  BaseSelectUserDefaultMultiDepartmentAndRoleOptions,
  BaseSelectUserBaseWindowDefaultOptions,
  BaseSelectUserSearchMoreTypeNameMap,
  BaseSelectUserDefaultMultiServiceProviderOptions,
  BaseSelectUserDefaultMultiDepartmentUserOptions,
  BaseSelectUserDynamicTab,
  ProductLineRoleMap
}
